﻿using System;

namespace PmfWeb.Core.Forms
{
    /// <summary>
    /// SiteIdentity站点身份类
    /// </summary>
    public class SiteIdentity : System.Security.Principal.IIdentity
    {
        #region 成员变量
        private string _userName;
        private int _userId;
        private string _linkQq;
        private string _loginIp;
        private DateTime _loginTime;
        private bool _isActivity;
        private bool _sex;
        private string _email;
        private string _realName;
        private string _phone;
        private byte[] _password;
        private string _roleId;
        #endregion

        #region 构造器
        ///<summary>
        ///</summary>
        ///<param name="userName"></param>
        ///<param name="linkQQ"></param>
        ///<param name="loginTime"></param>
        public SiteIdentity(string userName, string linkQQ, DateTime loginTime)
        {
            _userName = userName;
            _loginTime = loginTime;
            _linkQq = linkQQ;
        }
        ///<summary>
        ///</summary>
        ///<param name="id"></param>
        public SiteIdentity(int id)
        {
            //DALDatabase.SystemAdmin admin = new SystemAdmin();
            //DALDatabase.SystemAdminRole role=new SystemAdminRole();
            //Entity.SystemAdmin entity = admin.GetModel(id);
            //if (entity != null)
            //{
            //    _userName = entity.Name;
            //    _linkQq = entity.QQ;
            //    _loginIp = "";
            //    _loginTime = DateTime.Now;
            //    _userId = id;
            //    _isActivity = entity.IsActivity;
            //    _sex = entity.Sex;
            //    _email = entity.Email;
            //    _realName = entity.RealName;
            //    _phone = entity.Phone;
            //    _password = entity.Password;
            //}
            //DataTable dTable = role.GetList().Tables[0];
            //DataRow[] rows = dTable.Select("AdminID=" + _userId);
            //StringBuilder strRole = new StringBuilder();
            //for (int i = 0; i < rows.Length; i++)
            //{
            //    strRole.Append(Convert.IsDBNull(rows[i]["RoleID"]) ? "0" : rows[i]["RoleID"].ToString());
            //    strRole.Append(",");
            //}
            //_roleId = strRole.ToString();
        }
        #endregion

        #region IIdentity的成员
        ///<summary>
        ///</summary>
        public string Name
        {
            get { return _userName; }
        }

        ///<summary>
        ///</summary>
        public string AuthenticationType
        {
            get { return "自定义验证"; }
        }

        ///<summary>
        ///</summary>
        public bool IsAuthenticated
        {
            get { return true; }
        }
        #endregion

        #region 属性
        ///<summary>
        ///</summary>
        public virtual string UserName
        {
            get { return _userName; }
            set { _userName = value; }
        }
        ///<summary>
        ///</summary>
        public virtual string LinkQQ
        {
            get { return _linkQq.Replace(" ", ""); }
            set { _linkQq = value; }
        }

        ///<summary>
        ///</summary>
        public virtual string LoginIp
        {
            get { return _loginIp.Replace(" ", ""); }
            set { _loginIp = value; }
        }

        ///<summary>
        ///</summary>
        public virtual DateTime LoginTime
        {
            get { return _loginTime; }
            set { _loginTime = value; }
        }

        ///<summary>
        ///</summary>
        public virtual int UserID
        {
            get { return _userId; }
            set { _userId = value; }
        }

        ///<summary>
        ///</summary>
        public virtual bool IsActivity
        {
            get { return _isActivity; }
            set { _isActivity = value; }
        }

        ///<summary>
        ///</summary>
        public virtual bool Sex
        {
            get { return _sex; }
            set { _sex = value; }
        }

        ///<summary>
        ///</summary>
        public virtual string Email
        {
            get { return _email; }
            set { _email = value; }
        }

        ///<summary>
        ///</summary>
        public virtual string RealName
        {
            get { return _realName; }
            set { _realName = value; }
        }

        ///<summary>
        ///</summary>
        public virtual string Phone
        {
            get { return _phone; }
            set { _phone = value; }
        }

        ///<summary>
        ///</summary>
        public virtual byte[] Password
        {
            get { return _password; }
            set { _password = value; }
        }

        ///<summary>
        ///</summary>
        public virtual string RoleID
        {
            get { return _roleId; }
            set { _roleId = value; }
        }

        #endregion
    }
}